package com.example.kotlinstudy.基本语法

fun getStringLength(obj: Any): Int? {
//    if (obj is String) {
//        return obj.length
//    }
//    return null;

    if(obj !is String) {
        return null;
    }
    //obj自动转换为String
    return obj.length;

//    if (obj is String && obj.length > 0) {
//        return obj.length
//    }
//    return null;
}

fun main() {
    fun printLength(obj: Any) {
        println("Getting the length of '$obj'. Result: ${getStringLength(obj) ?: "Error: The object is not a string"}")
    }
    printLength("Incomprehensibility")
    printLength(1000)
    printLength(listOf(Any()))
}